package com.gz.mapper;

import com.gz.entity.Pet;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface PetMapperAnnotation {
    //通过user的id来获取pet对象，可能有多个
    @Select("select * from mybatis_pet where user_id=#{userId}")
    @Results(id = "PetResultMap",
            value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "nickName",column = "nickname"),
            @Result(property = "user",column = "user_id",
                    one = @One(select = "com.gz.mapper.UserMapperAnnotation.getUserById"))
    })
    public List<Pet> getPetByUserId(Integer userid);

    //通过pet的id获取pet对象
    @Select("select * from mybatis_pet where id=#{petId}")
    //复用 上面的PetResultMap
    @ResultMap("PetResultMap")
    public Pet getPetById(Integer petId);
}
